package com.tanguy.driver.base

import android.os.Build
import android.os.Bundle
import android.support.annotation.LayoutRes
import android.view.View
import cn.sinata.xldutils_kotlin.activity.TitleActivity
import com.tanguy.driver.R
import com.tanguy.driver.interfaces.RequestHelper
import com.tanguy.driver.utlis.ToastUtils
import io.reactivex.disposables.Disposable

/**
 * Created by dab on 2017/9/30 0030 09:03
 * 沉浸式
 */

abstract class ImmersionTitleActivity : TitleActivity(), RequestHelper {
    @LayoutRes
    abstract fun setContentViewRes(): Int

    var isVisibility = true
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(setContentViewRes())
        val status_bar: View = findViewById(R.id.view_status_bar)
        initStatusBar(status_bar)
        if (fullScreen()) {
            titleBar.visibility = View.GONE
            status_bar.visibility = View.GONE
        }
        initView()
        initEvent()
        initData()
    }

    open fun fullScreen(): Boolean = false
    open fun initEvent() {}
    open fun initData() {}
    open fun initView() {
        titleBar.setTitleColor(R.color.white)
    }

    private fun initStatusBar(view: View) {
        var statusBarHeight = 0
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
            //获取status_bar_height资源的ID
            val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
            if (resourceId > 0) {
                //根据资源ID获取响应的尺寸值
                statusBarHeight = resources.getDimensionPixelSize(resourceId)
            }
        }
        val layoutParams = view.layoutParams
        layoutParams.height = statusBarHeight
        view.layoutParams = layoutParams
    }


    override fun showToast(msg: String?) {
        ToastUtils.showToast(msg)
    }

    override fun showLoadDialog(msg: String, canCancel: Boolean) {
        showDialog(msg, false)
    }

    override fun dismissLoadDialog() {
        dismissDialog()
    }

    override fun cancelRequest(disposable: Disposable) {
        compositeDisposable.add(disposable)
    }







}
